package com.mit.wx.vo;

import com.alibaba.fastjson.JSON;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.Base64;

/**
 * 2018/10/23 Create by 郭文梁
 * WxLoginState
 * 微信登录时state数据封装
 *
 * @author 郭文梁
 * @date 2018/10/23
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class WxLoginState {
    public static WxLoginState fromBase64(String base64) {
        byte[] result = Base64.getDecoder().decode(base64);
        return JSON.parseObject(new String(result), WxLoginState.class);
    }

    private Integer adminId;
    private String key;

    public String toBase64() {
        String json = toJSON();
        return Base64.getEncoder().encodeToString(json.getBytes());
    }

    public String toJSON() {
        return JSON.toJSONString(this);
    }
}
